
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Oracle to java type
 */
public final class OracleTypeMapJavaType {
	 private final static Map map = new HashMap();
	 static{
		 map.put("CHAR", "String");
		 map.put("VARCHAR2", "String");
		 map.put("NUMBER", "int");
		 map.put("DATE", "java.util.Date");
		 map.put("TIMESTAMP(6)", "java.util.Date");
		 map.put("BLOB", "java.sql.Blob");
		 map.put("CLOB", "java.sql.Clob");
		 map.put("STRUCT", "java.sql.Struct");
	 }
	 public static String getJavaTypeFromOracleType(String oracleType,String defaultType){
		 Object obj=null;
		 if(defaultType==null){
			 obj= getJavaTypeFromOracleType(oracleType);
		 }else{
			 obj=map.get(oracleType);
		 }
		 if(obj==null){
			 return  defaultType;
		 }else{
			 return String.valueOf(obj);
		 }
	 }
	 public static String getJavaTypeFromOracleType(String oracleType){
		 Object obj=map.get(oracleType);
		 if(obj==null){
			 Set set =map.keySet();
			 Iterator it = set.iterator();
			 while(it.hasNext()){
				 String key = String.valueOf(it.next());
				 if(oracleType.indexOf(key)!=-1){
					 obj=map.get(key);
				 }
			 }
		 }
		 if(obj==null){
			 return null;
		 }
		 return String.valueOf(obj);
		 
	 }
}
